import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import VueDevTools from 'vite-plugin-vue-devtools'

import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import {viteMockServe} from "vite-plugin-mock";


// https://vitejs.dev/config/
export default defineConfig({
  css: {
    preprocessorOptions: {
      less: {
        // 这里是关键，启用对内联 JavaScript 的支持
        javascriptEnabled: true,
      },
    },
  },
  plugins: [
    vue(),
    vueJsx(),
    VueDevTools(),
    // 配置 unplugin-vue-components
    Components({
      resolvers: [
        AntDesignVueResolver(
            {
              importStyle: 'less', // 根据你的样式需求选择，这里假设你的项目使用 less
              resolveIcons: true, // 启用图标自动导入
            }
        ),
      ],
    }),
    viteMockServe({
      mockPath: 'src/mock', // 设置mock文件路径
      localEnabled: true, // 开发环境启用mock
      prodEnabled: false, // 生产环境禁用mock
      injectCode: `
        import { setupMockServer } from './mock';
        setupMockServer();
      `,
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
